# 周林浙
# 时间：2025/2/28 10:36
import random

def get_valid_guess():
    while True:
        try:
            guess = int(input("请输入一个数字（1-9）："))
            if 1 <= guess <= 9:
                return guess
            else:
                print("输入的数字不在1-9范围内，请重新输入。")
        except ValueError:
            print("输入无效，请输入一个整数。")

def play_game():
    secret_number = random.randint(1, 9)

    while True:
        guess = get_valid_guess()

        if guess == secret_number:
            print("恭喜，猜对了！")
            break
        elif guess < secret_number:
            print("猜小了，再试一次。")
        else:
            print("猜大了，再试一次。")

def main():
    while True:
        play_game()
        choice = input("是否继续游戏？(y/n): ").strip().lower()
        if choice != 'y':
            print("感谢游玩，再见！")
            break

if __name__ == "__main__":
    main()
